<?php

defined('DSVH') or die('Restricted access');
 
//add chuc danh
function inserttinhoatdong($local){
    mysql_query("insert tin_hoat_dong set ten_tin_hoat_dong = '".$local['ten_tin_hoat_dong']."',
    file = '".$local['file']."',
    general = '".$local['mo_ta_chung']."',
    cat_id = '".$local['cat_id']."',
    cat_id2 = '".$local['cat_id']."',
    can_bo_id = '".$_SESSION['can_bo_id']."',
    keyword = '".$local['keyword']."',
    add_date = NOW(),
    detail = '".$local['mo_ta_chi_tiet']."'", 
    dbconnect());
}
//list chuc danh
function getListtinhoatdong($start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM tin_hoat_dong
        left join can_bo ON tin_hoat_dong.can_bo_id = can_bo.can_bo_id
        left join cat_tin ON tin_hoat_dong.cat_id = cat_tin.cat_id 
        order by tin_hoat_dong_id desc LIMIT ".(int)$start.",".(int)$limit."
        ", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }



function insertcattin($local){
    mysql_query("insert cat_tin set ten_cat_tin ='".$local['ten_cat_tin']."',
    sap_xep = '".$local['sap_xep']."',
    can_bo_id = '".$_SESSION['cab_bo_id']."'", 
    dbconnect());
}

function editcattin($id, $local)
{
    mysql_query("update cat_tin set ten_cat_tin ='".$local['ten_cat_tin']."',
    sap_xep = '".$local['sap_xep']."',
    can_bo_id = '".$_SESSION['cab_bo_id']."' 
    where cat_id = '".(int)$id."'", dbconnect());
}
// xoa thu muc
function delcattin($id){
    mysql_query("delete from cat_tin where cat_id ='".(int)$id."'", dbconnect());
}

function totalcattin(){
   $result = mysql_query("select * from cat_tin",dbconnect());
    return mysql_num_rows($result);
}



function getlisttinhoatdongvoithamso($local, $start, $limit)
    {
        $sql = "SELECT * FROM tin_hoat_dong
        left join can_bo ON tin_hoat_dong.can_bo_id = can_bo.can_bo_id
        left join cat_tin ON tin_hoat_dong.cat_id = cat_tin.cat_id ";
      
        if($local['ten_tin_hoat_dong']){
            
            $sql .= "WHERE ten_tin_hoat_dong like '%".$local['ten_tin_hoat_dong']."%'";
            
        }
        
        if($local['cat_id']){
            
            $sql .= " and cat_tin.cat_id = '".$local['cat_id']."'";
            
        }
        
        $sql .= "order by tin_hoat_dong_id desc LIMIT ".(int)$start.",".(int)$limit."";
        
        $local_list = mysql_query($sql, dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }
    

function total2($local){
   $result = mysql_query("select * from tin_hoat_dong 
   WHERE ten_tin_hoat_dong like '%".$local['ten_tin_hoat_dong']."%'",dbconnect());
    return mysql_num_rows($result);
}


//ham lay du lieu phong ban theo id
function gettinhoatdong($id)
    {
    $pro = mysql_query("select * from tin_hoat_dong where tin_hoat_dong_id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
    
    function getcattin($id)
    {
    $pro = mysql_query("select * from cat_tin where cat_id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
//cap nhat trong muc sua
function edittinhoatdong($id, $local)
{
    mysql_query("update tin_hoat_dong set ten_tin_hoat_dong ='".$local['ten_tin_hoat_dong']."',
    file = '".$local['file']."',
    general = '".$local['mo_ta_chung']."',
    cat_id = '".$local['cat_id']."',
    cat_id2 = '".$local['cat_id']."',
    keyword = '".$local['keyword']."',
    add_date = NOW(),
    detail = '".$local['mo_ta_chi_tiet']."' 
    where tin_hoat_dong_id = '".(int)$id."'", dbconnect());
}
// xoa thu muc
function deltinhoatdong($id){
    mysql_query("delete from tin_hoat_dong where tin_hoat_dong_id ='".(int)$id."'", dbconnect());
}

function total(){
   $result = mysql_query("select * from tin_hoat_dong",dbconnect());
    return mysql_num_rows($result);
}

 function checkcanbo($param){
    $sql = "SELECT * FROM can_bo where tin_hoat_dong_id = '".escape($param)."'";
    $result = mysql_query($sql, dbconnect());
    return mysql_num_rows($result);
}

function check_hoso_pvt($param){
    $sql = "SELECT * FROM ho_so_phi_vat_the where tin_hoat_dong_id = '".escape($param)."'";
    $result = mysql_query($sql, dbconnect());
    return mysql_num_rows($result);
}

function getListCattin($start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM cat_tin
        order by sap_xep asc LIMIT ".(int)$start.",".(int)$limit."
        ", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }

?>